<?php 
class AdTransport extends Ad
{
	public $AdTransportId;
	public $Length;
	public $Width;
	public $FromCountry;
	public $FromCity;
	public $FromZip;
	public $ToCountry;
	public $ToCity;
	public $ToZip;
	public $FromDate;
	public $ToDate;
	public $StandingOrder;
	
	public function getAdTransportId() { return intval($this->AdTransportId); }
	public function getDistance() { return intval($this->LengthUsed); }
	public function getLength() { return intval($this->Length); }
	public function getWidth() { return intval($this->Width); }
	public function getFromDate($format = 'Y-m-d H:i:s') { return self::formatDateTime($this->FromDate, $format); }
	public function getToDate($format = 'Y-m-d H:i:s') { return self::formatDateTime($this->ToDate, $format); }
	public function getStandingOrder() { return intval($this->StandingOrder); }
	
	public function getUsePrice() { return 1; }
	public function getUseBrand() { return 0; }
	public function getUseYear() { return 0; }
	public function getUseModel() { return 0; }
	public function getUseIsNew() { return 0; }
	
	public function setAdTransportId($val) { $this->AdTransportId=intval($val); }
	public function setDistance($val) { $this->LengthUsed=intval($val); }
	public function setLength($val) { $this->Length=intval($val); }
	public function setWidth($val) { $this->Width=intval($val); }
	public function setFromDate($val) { $this->FromDate=self::formatDateTime($val); }
	public function setToDate($val) { $this->ToDate=self::formatDateTime($val); }
	public function setStandingOrder($val) { $this->StandingOrder=intval($val); }
	
	function update()
	{
		if((self::getId() > 0) && (self::getDataChanged()))
		{
			global $user;
			if(($user->getId() == self::getUserId()) || ($user->getLevel() > 4) || (defined('RUN_IMPORT')))
			{
				self::updateAd();
				
				if(self::getAdTransportId() > 0)
				{
					$sql  = 'UPDATE '.DB_PERFIX.'am_ads_transport SET ';
					$sql .= '`AdTransportId`='.self::getId().', ';
					$sql .= '`Length`='.self::getLength().', ';
					$sql .= '`Width`='.self::getWidth().', ';
					$sql .= '`FromCountry`="'.self::formatText(self::getFromCountry()).'", ';
					$sql .= '`FromCity`="'.self::formatText(self::getFromCity()).'", ';
					$sql .= '`FromZip`="'.self::formatText(self::getFromZip()).'", ';
					$sql .= '`ToCountry`="'.self::formatText(self::getToCountry()).'", ';
					$sql .= '`ToCity`="'.self::formatText(self::getToCity()).'", ';
					$sql .= '`ToZip`="'.self::formatText(self::getToZip()).'", ';
					$sql .= '`FromDate`="'.self::getFromDate().'", ';
					$sql .= '`ToDate`="'.self::getToDate().'", ';
					$sql .= '`StandingOrder`='.self::getStandingOrder().' ';
					$sql .= ' WHERE AdTransportId='.self::getId().' LIMIT 1;';
					mysql_query($sql);
				}
				else
				{
					$insert  = '`AdTransportId`';
					$values  = self::getId();
					$insert .= ', `Length`';
					$values .= ', '.self::getLength();
					$insert .= ', `Width`';
					$values .= ', '.self::getWidth();

					$insert .= ', `FromCountry`';
					$values .= ', "'.self::formatText(self::getFromCountry()).'"';
					$insert .= ', `FromCity`';
					$values .= ', "'.self::formatText(self::getFromCity()).'"';
					$insert .= ', `FromZip`';
					$values .= ', "'.self::formatText(self::getFromZip()).'"';
					
					$insert .= ', `ToCountry`';
					$values .= ', "'.self::formatText(self::getToCountry()).'"';
					$insert .= ', `ToCity`';
					$values .= ', "'.self::formatText(self::getToCity()).'"';
					$insert .= ', `ToZip`';
					$values .= ', "'.self::formatText(self::getToZip()).'"';
					
					$insert .= ', `FromDate`';
					$values .= ', "'.self::getFromDate().'"';
					$insert .= ', `ToDate`';
					$values .= ', "'.self::getToDate().'"';
					
					$insert .= ', `StandingOrder`';
					$values .= ', '.self::getStandingOrder().' ';
					
					$sql  = 'INSERT INTO '.DB_PERFIX.'am_ads_transport ('.$insert.') '; 
					$sql .= 'VALUES ('.$values.');';
					$result = mysql_query($sql);
				}
			}
		}
	}
}
?>